package com.security.user.controller;

import com.lambdaworks.crypto.SCryptUtil;
import com.security.user.mapper.UserInfoMapper;
import com.security.user.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author yanggld
 * @Date 2020/3/9-12:17
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    public UserInfoMapper userInfoMapper;

    @GetMapping("/{id}")
    public UserInfo get(@PathVariable Long id) {
        if (id == 2) {
            throw new RuntimeException("非法操作");
        }
        return new UserInfo(1L, "张三", "", "");
    }

    @PostMapping
    public UserInfo save(@RequestBody UserInfo userInfo) {
        userInfo.setPassword(SCryptUtil.scrypt(userInfo.getPassword(), 16, 16, 16));
        userInfoMapper.save(userInfo);
        return userInfo;
    }
}